package com.ityc.mapper;

import com.ityc.pojo.Emp;
import com.ityc.pojo.EmpQueryParam;
import org.apache.ibatis.annotations.*;

import java.time.LocalDate;
import java.util.List;
import java.util.Map;

@Mapper
public interface EmpMapper {

//    @Select("select count(*) from emp e left join dept d on dept_id = d.id")
//    Long count();

//    @Select("select e.*,d.name deptName from emp e left join dept d on dept_id = d.id " +
//            "order by e.update_time desc limit #{start},#{pageSize}")
//    List<Emp> list(Integer start, Integer pageSize);

    //@Select("select e.*,d.name deptName from emp e left join dept d on dept_id = d.id order by e.update_time desc")
//    List<Emp> list(String name, Integer gender, LocalDate begin, LocalDate end);
    List<Emp> list(EmpQueryParam empQueryParam);

    @Options(useGeneratedKeys = true, keyProperty = "id")
    @Insert("insert into emp(username,name,gender,phone,job,salary,image,entry_date,dept_id,create_time,update_time) "
            + "values (#{username},#{name},#{gender},#{phone},#{job},#{salary},#{image},#{entryDate},#{deptId},#{createTime},#{updateTime})")
    void insert(Emp emp);


    void deleteByIds(List<Integer> ids);

    Emp getById(Integer id);

    void updateById(Emp emp);

    @MapKey("pos")
    List<Map<String, Object>> CountEmpJobData();

    @MapKey("name")
    List<Map<String, Object>> CountEmpGenderData();

    @Select("select id, username, password, name, gender, phone, job, salary, image, entry_date, dept_id, create_time, update_time from emp order by update_time desc")
    List<Emp> findAll();

    @Select("select count(*) from emp where dept_id = #{id}")
    Integer countByDeptId(Integer id);

    @Select("select id, username, name from emp where username = #{username} and password = #{password}")
    Emp selectByUsernameAndPassword(String username, String password);
}
